import openpyxl
from openpyxl.styles import Alignment

# Excel名称
excel_name = '02.xlsx'

# 读取Excel
wb = openpyxl.load_workbook(excel_name)

# 读取工作簿
ws = wb.active

# 设置每一行每一列单元格居中
for i in range(1, ws.max_row + 1):  # 行
    for j in range(1, ws.max_column + 1):  # 列
        ws.cell(row=i, column=j) \
            .alignment = Alignment(horizontal='center', vertical='center')

# 保存
wb.save(excel_name)
